---
# tasklist for setting up the mirrormanager web application

- name: clean yum metadata
  command: yum clean all
  tags:
  - mm2_frontend
  - packages

- name: install needed packages
  yum: pkg={{ item }} state=present
  with_items:
  - mirrormanager2
  - python-psycopg2
  - python-openid-cla
  - python-openid-teams
  - python-memcached
  - libsemanage-python
  tags:
  - mm2_frontend
  - packages

- name: install configuration file
  template: src={{ item.file }} dest={{ item.dest }}
            owner=apache group=apache mode=0600
  with_items:
  - { file: mirrormanager.conf, dest: /etc/httpd/conf.d/mirrormanager.conf }
  - { file: mirrormanager2.cfg, dest: /etc/mirrormanager/mirrormanager2.cfg }
  - { file: alembic.ini, dest: /etc/mirrormanager/alembic.ini }
  - { file: mirrormanager2.wsgi, dest: /var/www/mirrormanager2.wsgi }
  notify:
  - reload httpd
  tags:
  - mm2_frontend
  - config

- name: create the database scheme
  command: /usr/bin/python2 /usr/share/mirrormanager2/mirrormanager2_createdb.py
  environment:
      MM2_CONFIG: /etc/mirrormanager/mirrormanager2.cfg
  tags:
  - mm2_frontend
  - config

- name: set sebooleans so mirrormanager can connect to its db
  action: seboolean name=httpd_can_network_connect_db
                    state=true
                    persistent=true
  tags:
  - mm2_frontend
  - config

- name: startup apache
  service: name=httpd enabled=yes state=started
  tags:
  - mm2_frontend
  - config

- name: Create mirrormanager user
  user: name=mirrormanager state=present home=/var/lib/mirrormanager createhome=yes shell=/sbin/nologin
  tags:
  - mm2_frontend
  - config

- name: create /var/log/mirrormanager/crawler
  file: path=/var/log/mirrormanager/crawler state=directory owner=mirrormanager group=mirrormanager mode=0755
  tags:
  - mm2_frontend
  - config

- name: apply selinux type to crawler log files
  file: >
    dest=/var/log/mirrormanager/crawler
    setype=httpd_sys_content_t
    state=directory
    recurse=yes
  tags:
  - mm2_frontend
  - config

- name: install crawler log sync
  template: src=sync-crawler-logs.sh dest=/usr/local/bin/sync-crawler-logs.sh mode=0755
  tags:
  - mm2_frontend

- name: install the cron job
  template: src=frontend.cron dest=/etc/cron.d/mm2_frontend.cron
  tags:
  - config
  - mm2_frontend
  when: env != "staging"
